﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UserLoginTest
{
    public partial class Form1 : common.frmBase
    {
        public Form1()
        {
            InitializeComponent();
            AppName = "Test";
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            txtAPPName.Text = AppName;
        }

        private void frmAPP_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
            OUtl.OutputBox.CloseConsole();
        }

        private void frmCheckUser_FormClosed(object sender, FormClosedEventArgs e)
        {
            ExitAPP();
        }

        #region >>ServerIP Set<<
        private void serverToolStripMenuItem_Click(object sender, EventArgs e)
        {
            setSetverIP();
        }

        protected override void ServerIPset()
        {
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            UserName = txtUserName.Text;
            Password = txtPassword.Text;

            if (string.IsNullOrWhiteSpace(UserName) || string.IsNullOrWhiteSpace(Password))
                MessageBox.Show("需要帳號或密碼");
            else
                userStart();
        }

        protected override void Start(bool isStop)
        {
            if (isStop)
            {
                button1.Text = "Login";
            }
            else
            {
                button1.Text = "Logout";

            }
        }

        protected override void clientUser_ClientStateEvent(object sender, TCPGolbalInfo.FlagEnum flag)
        {
            if (flag == TCPGolbalInfo.FlagEnum.LoginOK)
            {
                MessageBox.Show("登入成功");
            }
            else if (flag == TCPGolbalInfo.FlagEnum.LoginFail || flag == TCPGolbalInfo.FlagEnum.Logout)
            {
                MessageBox.Show("登入失敗");
                userStart();
            }
            else
            {
                Console.WriteLine(flag.ToString());
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            AppName = txtAPPName.Text;
        }

    }
}
